package com.initialize.pub.dao;

import com.initialize.pub.generate.pojo.Article;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.type.JdbcType;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * Created with IntelliJ IDEA.
 * User: jane
 * Date: 2020/2/28
 * Time: 6:22 下午
 * Description:
 */
@Repository
public interface ArticleDAO {
    List<Article> getRecommendedArticles();

    @Select({
            "SELECT * FROM article where status = 1"
    })
    @Results({
            @Result(column = "aid", property = "aid", jdbcType = JdbcType.INTEGER, id = true),
            @Result(column = "title", property = "title", jdbcType = JdbcType.VARCHAR),
            @Result(column = "classification", property = "classification", jdbcType = JdbcType.INTEGER),
            @Result(column = "label", property = "label", jdbcType = JdbcType.VARCHAR),
            @Result(column = "release_time", property = "releaseTime", jdbcType = JdbcType.TIMESTAMP),
            @Result(column = "update_time", property = "updateTime", jdbcType = JdbcType.TIMESTAMP),
            @Result(column = "browse_the_number", property = "browseTheNumber", jdbcType = JdbcType.INTEGER),
            @Result(column = "thumb_up_number", property = "thumbUpNumber", jdbcType = JdbcType.INTEGER),
            @Result(column = "status", property = "status", jdbcType = JdbcType.INTEGER),
            @Result(column = "content", property = "content", jdbcType = JdbcType.LONGVARCHAR)
    })
    List<Article> getAListOfArticles();

    @Select({
            "SELECT * FROM article WHERE classification = #{cid}"
    })
    @Results({
            @Result(column = "aid", property = "aid", jdbcType = JdbcType.INTEGER, id = true),
            @Result(column = "title", property = "title", jdbcType = JdbcType.VARCHAR),
            @Result(column = "classification", property = "classification", jdbcType = JdbcType.INTEGER),
            @Result(column = "label", property = "label", jdbcType = JdbcType.VARCHAR),
            @Result(column = "release_time", property = "releaseTime", jdbcType = JdbcType.TIMESTAMP),
            @Result(column = "update_time", property = "updateTime", jdbcType = JdbcType.TIMESTAMP),
            @Result(column = "browse_the_number", property = "browseTheNumber", jdbcType = JdbcType.INTEGER),
            @Result(column = "thumb_up_number", property = "thumbUpNumber", jdbcType = JdbcType.INTEGER),
            @Result(column = "status", property = "status", jdbcType = JdbcType.INTEGER),
            @Result(column = "content", property = "content", jdbcType = JdbcType.LONGVARCHAR)
    })
    List<Article> selByLabel(@Param("cid") int cid);

    @Select({
            "SELECT COUNT(aid) FROM article"
    })
    int selALlNum();

//    List<Article>

}